class Solution {
public:
    bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
        //使用栈进行模拟
        stack<int>st;
        int out_index=0;
        for(auto e:pushed)
        {
            st.push(e);
            while(!st.empty()&&st.top()==popped[out_index])//栈不为空且栈顶等于弹出
            {
                st.pop();
                ++out_index;
            }
        }
        return st.empty();
    }
};